﻿using System;
using System.Text;
using System.Drawing;
using Microsoft.Win32;
using System.Collections.Generic;

namespace Omega.Editor.Classes
{
    static public class Registro
    {

        static public bool VerificaChave(string cPasta, string cChave)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta + cChave);

            return regKey != null;
        }

        static public bool VerificaChave(string cPasta, string cChave , String cValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta + cChave);
            regKey.SetValue(cChave, cValor);

            return regKey != null;
        }

        static public void Gravar(string cChave, string cValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega");
            regKey.SetValue(cChave, cValor);
        }

        static public void Gravar(string cPasta, string cChave, string cValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);
            regKey.SetValue(cChave, cValor);
        }

        static public void Gravar(string cPasta, string cChave, Color oCor)
        {
            int nR, nG, nB = 0;
            nR = (int)oCor.R;
            nG = (int)oCor.G;
            nB = (int)oCor.B;
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);
            regKey.SetValue(cChave + "_R", nR);
            regKey.SetValue(cChave + "_G", nG);
            regKey.SetValue(cChave + "_B", nB);
        }

        static public void Gravar(string cPasta, string cChave, int nValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);
            regKey.SetValue(cChave, nValor);
        }

        static public void Gravar(string cPasta, string cChave, Boolean lValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);
            regKey.SetValue(cChave, lValor);
        }

        static public void Gravar(string cChave, int nValor)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega");
            regKey.SetValue(cChave, nValor);
        }

        static public string Ler(string cChave, string cValorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega");

            string cValor = (string)regKey.GetValue(cChave, cValorPadrao);
            return cValor;
        }

        static public string Ler(string cPasta, string cChave, string cValorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);

            string cValor = (string)regKey.GetValue(cChave, cValorPadrao);
            return cValor;
        }

        static public Color Ler(string cPasta, string cChave, Color oCorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);

            int nR = (int)regKey.GetValue(cChave + "_R", (int)oCorPadrao.R);
            int nG = (int)regKey.GetValue(cChave + "_G", (int)oCorPadrao.G);
            int nB = (int)regKey.GetValue(cChave + "_B", (int)oCorPadrao.B);

            Color oCor = Color.FromArgb(nR, nG, nB);
            return oCor;
        }

        static public int Ler(string cChave, int nValorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega");

            int nValor = (int)regKey.GetValue(cChave, nValorPadrao);
            return nValor;
        }
        static public int Ler(string cPasta, string cChave, int nValorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);

            int nValor = (int)regKey.GetValue(cChave, nValorPadrao);
            return nValor;
        }
        static public Boolean Ler(string cPasta, string cChave, Boolean lValorPadrao)
        {
            RegistryKey hklm = Registry.CurrentUser;
            RegistryKey regKey = hklm.CreateSubKey("Software\\Omega\\" + cPasta);
            object oAux = regKey.GetValue(cChave, lValorPadrao);
            Boolean lValor = false;
            if (oAux == null || oAux.ToString() == String.Empty)
                lValor = lValorPadrao;
            else
                lValor = (oAux.ToString() == "True");
            return lValor;
        }
    }
}
